package com.wxchat.chat.util;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import net.sf.json.JSONObject;

/*****
 * 微信公共方法
 * @author Thinkpad
 *
 */
public class WxChatUtils {

//	放入当前公众号的appiD和Appsercet
	public static final String APP_ID="wx2180e022ed8c0b84";
	public static final String APP_SECRET="576af74776fcc3fab8f65a8a3033081f";
	
	
//	String url地址
	public static JSONObject getJSONObject(String url) throws ClientProtocolException, IOException{
		JSONObject fromObject = null;
		//初始化一个对象
		DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
		/***
		 * 通过get方法提交
		 * 并传入地址
		 */
		HttpGet httpGet = new HttpGet(url);
		//发送请求
		HttpResponse execute = defaultHttpClient.execute(httpGet);
		//返回结果
		HttpEntity entity = execute.getEntity();
		if(execute!=null){
			//把返回的结果转换成String类型
			String string = EntityUtils.toString(entity,"utf-8");
			//String类型转换成json格式
			fromObject = JSONObject.fromObject(string);
		}
		httpGet.releaseConnection();
		return fromObject;
	}
	
			
	
}
